import loading from "./loading";
import service from "./service/cimrtsService";

import { getProjectManager } from "@/scripts/getProjectManager";

const cimretBaseUrl = () => {
    const objm = getProjectManager()
    return objm.cimrtsManager.cimrtsUrl.match(/^(https?:\/\/[^\/]+)/)?.[1]
}

/**
 * 获取单个切片服务
 * @param {*} tileServiceName  切片服务名称
 * @returns 
 */
export const reqGetOneTileService = (tileServiceName: string) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/info/${tileServiceName}`,
        method: "get",
    })
    return getInfoData

}

/**
 * 获取系统配置
 */
export const reqGetSetting = () => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/system/setting/get`,
        method: 'get',

    })
    return getInfoData
}

/**
 * 框选查询
 * @param {*} data
 * @returns 
 */
export const reqGetSelectQuery = (data: any = {}) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/editor/querybyrect`,
        method: 'post',
        data
    })
    return getInfoData
}


/**
 * 水面修补
 * @param {*} data
 * @returns 
 */
export const reqWaterRepair = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/waterrepair`,
        method: 'post',
        data
    })
    return getInfoData
}


/**
 * 获取基础属性配置（筛选作用）
 * @param {*} tileServiceName 
 * @returns 
 */
export const reqGetbpcByStore = (tileServiceName: string) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/property/bpc/get?tileServiceName=${tileServiceName}`,
        method: 'post',
    })
    return getInfoData
}

/**
 * 纹理列表
 * @param {*} data 
 * @returns 
 */
export const reqGetTextureList = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/texture/list`,
        method: 'post',
        data
    })
    return getInfoData
}

/**
 * 多项操作
 * @param {*} data 
 * @returns 
 */
export const reqEditorMultioperation = (data: any) => {
    loading.showLoading("正在提交任务，请稍后...")
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/multioperation`,
        method: 'post',
        data
    })
    return getInfoData
}

/**
 * 获取图层树列表
 * @param {*} tileServiceName 
 * @returns 
 */
export const getVirtualList = (tileServiceName: string) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/layer/tree?tileServiceName=${tileServiceName}`,
        method: 'get'
    })
    return getInfoData
}

/**
 * 面
 * @param data 
 * @returns 
 */
export const createPolygon = (data: any = {}) => {
    const updateData = service({
        url: `${cimretBaseUrl()}/system/util/polygon/getpoints`,
        method: "post",
        data,
    })
    return updateData
}

/**
 * 创建
 * @param data 
 * @returns 
 */
export const createFeature = (data: any = {}) => {
    const updateData = service({
        url: `${cimretBaseUrl()}/ds/editor/batchcreate`,
        method: "post",
        data,
    })
    return updateData
}

/**
 * 几何库列表（资源库）
 * @param data 
 * @returns 
 */
export const getGeometryList = (data: any = {}) => {
    const updateData = service({
        url: `${cimretBaseUrl()}/ds/geometry/list`,
        method: "post",
        data,
    })
    return updateData
}

/**
 * 获取几何体列表(数据集)
 * @param {*} data 
 * @returns 
 */
// export const getDatasetGeometryList = (data: any = {}) => {
//     const getInfoData = service({
//         url: `${cimretBaseUrl()}/ds/geometry/list`,
//         method: 'post',
//         data
//     })
//     return getInfoData
// }

/**
 * 获取所有要素筛选中的数据集
 * @param tileServiceName 
 * @returns 
 */
export const getFeatureDataset = (tileServiceName: string) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/featureselector/datasets?tileServiceName=${tileServiceName}`,
        method: 'get'
    })
    return getInfoData
}

/**
 * 获取要素类派生树
 * @param datasetName 数据集名称
 * @returns 
 */
export const getFeatureClassTree = (datasetName: string) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/featureclass/tree?datasetName=${datasetName}`,
        method: 'get'
    })
    return getInfoData
}

/**
 * 根据图层获取其下所有要素的范围
 * @param data
 * @returns 
 */
export const reqQueryBoxByLayer = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/editor/queryboxbylayer`,
        method: 'post',
        data
    })
    return getInfoData
}

/**
 * 随机返回一个要素信息(用于定位)
 * @param data
 * @returns 
 */
export const reqRandomfeature = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/editor/randomfeature`,
        method: 'post',
        data
    })
    return getInfoData
}

// 切片服务列表
export const reqGetRecordList = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ts/record/list`,
        method: 'post',
        data
    })
    return getInfoData
}

// 重命名材质
export const reqRenameMaterial = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/renamematerial`,
        method: 'post',
        data
    })
    return getInfoData
}

// 克隆材质
export const reqCloneMaterial = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/clonematerial`,
        method: 'post',
        data
    })
    return getInfoData
}

// 编辑材质
export const reqUpdateMaterial = (data: any) => {
    loading.showLoading("正在编辑材质，请稍后...")
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/updatematerial`,
        method: 'post',
        data
    })
    return getInfoData
}

// 删除材质
export const reqDeleteMaterial = (data: any) => {
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/deletematerial`,
        method: 'post',
        data
    })
    return getInfoData
}

// 修改要素对应几何体的清晰度
export const reqChangeDefinitionl = (data: any) => {
    loading.showLoading("正在修改要素对应几何体的清晰度，请稍后...")
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/changeqingxidu`,
        method: 'post',
        data
    })
    return getInfoData
}

// 克隆纹理
export const reqCloneTexture = (data: any) => {
    loading.showLoading("正在克隆纹理，请稍后...")
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/clonetexture`,
        method: 'post',
        data
    })
    return getInfoData
}

// 克隆纹理
export const reqCreatethumb = (data: any) => {
    loading.showLoading("正在生成材质缩略图，请稍后...")
    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/editor/material/createthumb`,
        method: 'post',
        data
    })
    return getInfoData
}

/**
 * 生成几何体的缩略图
 * @param {*} data 
 * @returns 
 */
export const reqCreateGltfThumb = (data:any) => {
    loading.showLoading("正在生成几何体缩略图，请稍后...")

    const getInfoData = service({
        url: `${cimretBaseUrl()}/ds/gltf/createthumb`,
        method: 'post',
        data
    })
    return getInfoData
}

